<?php

namespace app\admin\service\yun;

use app\admin\model\yun\YunPhoneCdkBatch;
use app\admin\service\BaseService;


/**
 * 云挂机服务类
 */
class BoxYunCdkBatchService extends BaseService
{

    /**
     * @var YunPhoneCdkBatch
     */
    protected $model;

    public function __construct()
    {
        $this->model = new YunPhoneCdkBatch();
    }

    public function getList(): array
    {
        $params = request()->param();
        $page   = request()->param('page', 1);
        $limit  = request()->param('limit', 10);
        $name   = $params['name'] ?? '';
        $status = $params['status'] ?? '';
        $type   = $params['use_type'] ?? '';
        $is_fast= $params['is_fast'] ?? '';

        if (!empty($name)) $where[] = ['name', 'like', '%' . $name . '%'];
        if (!empty($status)) $where[] = ['status', '=', $status];
        if (isset($type) && $type != '') $where[] = ['use_type', '=', $type];
        if (isset($is_fast) && $is_fast != '') $where[] = ['is_fast', '=', $is_fast];
        if($limit == 9999999){
            $where[] =  ['is_fast', '=', 0];
        }

        $where[] = ['mark', '=', 1];
        $list    = $this->model->where($where)->page($page, $limit)->order('id', 'desc')->select();
        //返回结果
        $count = $this->model->where($where)->count();
        return array (
            "msg"   => '操作成功',
            "code"  => 0,
            "data"  => $list,
            "count" => $count,
        );
    }

    /**
     * 添加或编辑
     * @return mixed
     * @since 2021/6/9
     * @author ZhangXuanNeng
     */
    public function edit()
    {
        // 参数
        $data = request()->param();
        $id = $data['id'] ?? 0;
        if(!$id){
            $data['created_time'] = date('Y-m-d H:i:s');
        }
        $data['updated_time'] = date('Y-m-d H:i:s');
        return parent::edit($data); // TODO: Change the autogenerated stub
    }

    public function delete()
    {
        return parent::delete(); // TODO: Change the autogenerated stub
    }
}